Find the product of
two integers.
Input. Two integers a and b (a, b ≤ 109).
Output. Print the product of two
integers.
Sample
input |
Sample
output |
3
7 |
21 |
simple problem
Since a, b ≤ 109, then a
* b ≤ 1018.
Therefore, a 64-bit long long type should be used.
Read the values of the variables a and b.
scanf("%lld %lld", &a, &b);
Compute and print the product a * b.
p
= a * b;
printf("%lld\n", p);
#include <stdio.h>
#include <malloc.h>
long long *a, *b, *res;
int main()
{
a = (long long *)malloc(8);
b = (long long *)malloc(8);
scanf("%lld %lld", a, b);
res = (long long *)malloc(8);
*res = *a * *b;
printf("%lld\n", *res);
free(a); free(b); free(res);
return 0;
}
Java realization
import java.util.*;
public class Main
{
public static void
main(String[] args)
{
Scanner con = new
Scanner(System.in);
long a = con.nextLong();
long b = con.nextLong();
long res = a * b;
System.out.println(res);
con.close();
}
}
Java realization – class
MultInteger
import java.util.*;
class MultInteger
{
private long a;
MultInteger(long a)
{
this.a = a;
}
MultInteger
Mult(MultInteger b)
{
return new
MultInteger(a * b.a);
}
public String
toString()
{
return String.valueOf(a);
}
}
public class Main
{
public static void
main(String[] args)
{
Scanner con = new
Scanner(System.in);
MultInteger a = new
MultInteger(con.nextLong());
MultInteger b = new
MultInteger(con.nextLong());
MultInteger res = a.Mult(b);
System.out.println(res);
con.close();
}
}
Python realization
Read the values of the variables a and b.
a, b = map(int,input().split())
Compute and print the product a * b.
res = a * b
print(res)